package com.cqyc.imview.dialog

import android.app.Dialog
import android.content.Context
import android.view.animation.AnimationUtils
import android.widget.ImageView
import com.cqyc.imview.R


class LoadingDialog(c: Context) {
    private val context = c
    private val dialog: Dialog = Dialog(context)
    private var image: ImageView? = null

    init {
        //        dialog.setCanceledOnTouchOutside(false)
        dialog.window!!.setBackgroundDrawableResource(android.R.color.transparent)
        dialog.setContentView(R.layout.dialog_loading)
        image = dialog.findViewById(R.id.image)
    }

    fun isShowing(): Boolean {
        return dialog.isShowing
    }

    fun show() {
        dialog.show()
        val animation = AnimationUtils.loadAnimation(context, R.anim.anim_loading)
        image!!.startAnimation(animation)
    }

    fun dismiss() {
        if (isShowing())
            dialog.dismiss()
    }


}